import Taro from '@tarojs/taro';
import { satffInfo, userbd, yginfo } from '@api/home';
export default {
  install(Vue, options) {
    Vue.prototype.$reguser = function(_options, callback) {
      var _that = this;
      //_that.loadding();
      Taro.checkSession({
        success: function() {
          console.log('session 未过期');
          typeof callback == 'function' && callback();
        },
        fail: function() {
          console.log('session 登录态过期');
        },
      });
    };
    Vue.prototype.$getuserinfo = function(callback, options) {
      // var _that = this;
      // var gsid = Taro.getStorageSync('gsid'); //获取公司id
      yginfo({ gsid: options || '' }).then(data => {
        typeof callback == 'function' && callback(data);
      });
    };
    //工资绑定是查询
    Vue.prototype.$getuserbd = function(callback, options) {
      var _that = this;
      var gsid = Taro.getStorageSync('gsid'); //获取公司id
      userbd({ gsid: gsid }).then(data => {
        typeof callback == 'function' && callback(data);
      });
    };
    //工资绑定是查询
    Vue.prototype.$isLogin = function(callback, options) {
      var that = this;
      //获取本地sessinid
      var session_id = Taro.getStorageSync('session_id');
      //获取扫码进入id
      var gsid = Taro.getStorageSync('gsid');
      this.gsid = Taro.getStorageSync('gsid');
      let p = new Promise(function(res,rej){
        if (session_id.length < 1) {
          rej('未登录')
          Taro.showModal({
            title: '提示',
            content: '本操作需要登录，请登录',
            success(res) {
              if (res.confirm) {
                Taro.navigateTo({
                  url: '/pages/login/index',
                });
              } else if (res.cancel) {
                Taro.reLaunch({
                  url: '/pages/index/index',
                });
                //   Taro.navigateBack({
                //    delta: 2
                // });
              }
            },
          });
        }else{
          res('已登录')
        }
      })
      return p
    };
  },
};
